Formula Database Tutorial

outline:
1. How to better write your formulas in the database.
2. Comming soon!
[1]:
import numpy as np
import pandas as pd
import sympy as sp

import FormulaLab as fl

1. How to write your formulas in the database

FormulaLab has specific assumptions when reading formulas, such as:

1. Case sensitivity. (A does not equal a)
2. Follows python syntax, such as, power (**) not (^)
3. Follow SymPy syntax, such as, sin, cos, integrate, diff, ...
4. All different variables must have different names in one database,
to avoid mixing physics!
5. Constants should ends with "_" (eg., speed_of_light_, plank_, gravity_).
   Because constants does not help with derivation and slow the searching
   speed.
6. (Optional) It is recomended to use capital letters with Vector quantities
and small letters with scalar quantities(eg., Force, mass).
(FormulaLab will tell the difference in future versions)

Suggestions:

1- Write a full and uniqe name of all of the variables in your formula
database.
2- Add as many column in your database as you can, so you can use them
later as filters.
Because formulas can be mixed with unrelated field of study, which leads
to wrong answers.
3- Add underscore "_" at the end of constants.
[2]:
# Example of a formula database
df = pd.read_csv('Example Database.csv')
df
[2]:
ID Formula Field Reference Note
0 1 Displacement = Velocity * time Mechanics NaN NaN
1 2 Acceleration = Velocity / time Mechanics NaN NaN
2 3 Force = mass * Acceleration Mechanics NaN NaN
3 4 Weight = mass * Gravety Mechanics NaN NaN
4 5 Momentum = mass * Velocity Mechanics NaN NaN
5 6 Centerpetal_acceleration = Velocity**2 / radious Mechanics NaN NaN
6 7 work = Force * Displacement Mechanics NaN NaN
7 8 Kinetic_energy = mass * Velocity**2 / 2 Mechanics NaN NaN
8 9 Power = work / time Mechanics NaN NaN
9 10 pressure = Force / Area Mechanics NaN NaN
10 11 frequency = c_ / wavelength Waves NaN NaN
11 12 time_perioud = 1 / frequency Waves NaN NaN
12 13 refractive_index = c_ / Velocity Waves NaN NaN
13 14 Electric_field = Force / charge EM NaN NaN
14 15 Electric_potential = Electric_field * Displace... EM NaN NaN
[3]:
phyfos = fl.FormulaSearch(data=df, formula_col='Formula')
[4]:
d = phyfos.find('Displacement','time')
d
[4]:
[Velocity*time]
[5]:
d = phyfos.derive('Displacement','time')
d
[5]:
[Velocity*time,
 Acceleration*time**2,
 time*work/(Velocity*mass),
 Power*time/Force]
[6]:
wl = phyfos.find('wavelength',id=11)
wl
[6]:
[c/frequency]